package com.woniuxy.hospital;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.woniuxy.hospital.shiro.GobalCrossFilter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;

@EnableCaching
@SpringBootApplication
@MapperScan("com.woniuxy.hospital.mapper")
public class HplManageSystemApplication {

    public static void main(String[] args) {
        SpringApplication.run(HplManageSystemApplication.class, args);
    }

    //分页
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
    @Bean
    public FilterRegistrationBean<GobalCrossFilter> registrationFilterBean() {
        FilterRegistrationBean<GobalCrossFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new GobalCrossFilter()); // 注册 Filter
        filterRegistrationBean.addUrlPatterns("/*"); // 设置拦截哪些 URL
        filterRegistrationBean.setOrder(0);//优先级
        filterRegistrationBean.setEnabled(true);// 是否启用，如果值为false，则不启用该 Filter
        return filterRegistrationBean;
    }
}
